import io
import json
import os

from openai import OpenAI

from pydub import AudioSegment
client = OpenAI(api_key=os.environ["OPENAI_API_KEY_ZHIHU"], base_url=os.environ["OPENAI_API_BASE_ZHIHU"])
# fname = "C:/Users/赵刚/Downloads/ns364.mp3"
# audio = AudioSegment.from_file(fname, format="mp3")
# # only use first 5sec
# audio = audio[:5000]
#
# buffer = io.BytesIO()
# # you need to set the name with the extension
# buffer.name = fname
# audio.export(buffer, format="mp3")

filepath = r"C:/Users/赵刚/Downloads/ns364.mp3"
filedata=open(filepath,'rb')
transcript = client.audio.transcriptions.create(model="whisper-1",file=filedata)
print(transcript)